package LeetCode.exercise;

public class LC714 {
    public int maxProfit(int[] prices, int fee) {
        int n = prices.length;
        int[] dp1 = new int[n], dp2 = new int[n];
        dp1[0] = -prices[0];
        for(int i = 1; i < n; i++){
            dp1[i] = Math.max(dp2[i-1] - prices[i], dp1[i-1]);
            dp2[i] = Math.max(dp2[i-1], dp1[i-1] + prices[i] - fee);
        }
        return Math.max(dp1[n-1], dp2[n-1]);
    }
}
